const { ccclass, property, requireComponent,menu } = cc._decorator;

@ccclass
@menu('cccframework/Dissolution')
@requireComponent(cc.Sprite)
export default class Dissolution extends cc.Component {


    @property(cc.Float)
    fadeRate: number = 0.1;

    onLoad() {
        let sprite = this.node.getComponent(cc.Sprite);
        let mat = sprite.getMaterial(0)
        if (typeof mat.getProperty('fadeRate') != 'number') {
            return console.error('材质错误');
        }
        cc.tween(this)
            .repeatForever(
                cc.tween()
                    .to(3, { fadeRate: 1 })
                    .delay(2)
                    .to(3, { fadeRate: 0 })
                    .delay(2)
            )
            .start()
    }

    updateMaterial() {
        let sprite = this.node.getComponent(cc.Sprite);
        let mat = sprite.getMaterial(0)
        if (typeof mat.getProperty('fadeRate') != 'number') {
            return;
        }
        mat.setProperty('fadeRate', this.fadeRate)
        sprite.setMaterial(0, mat);

    }

    update(dt) {
        this.updateMaterial();
    }
}
